package day0415;

public class Calculator {
    // 定义三个 float 类型的私有成员属性
    private float javaGrade;
    private float cSharpGrade;
    private float databaseGrade;

    // 无参构造方法
    public Calculator() {
    }

    // 带参数的构造方法
    public Calculator(float javaGrade, float cSharpGrade, float databaseGrade) {
        this.javaGrade = javaGrade;
        this.cSharpGrade = cSharpGrade;
        this.databaseGrade = databaseGrade;
    }

    // Java 成绩的 getter 方法
    public float getJavaGrade() {
        return javaGrade;
    }

    // Java 成绩的 setter 方法
    public void setJavaGrade(float javaGrade) {
        this.javaGrade = javaGrade;
    }

    // C# 成绩的 getter 方法
    public float getCSharpGrade() {
        return cSharpGrade;
    }

    // C# 成绩的 setter 方法
    public void setCSharpGrade(float cSharpGrade) {
        this.cSharpGrade = cSharpGrade;
    }

    // 数据库成绩的 getter 方法
    public float getDatabaseGrade() {
        return databaseGrade;
    }

    // 数据库成绩的 setter 方法
    public void setDatabaseGrade(float databaseGrade) {
        this.databaseGrade = databaseGrade;
    }

    // 计算三个科目的平均值的方法
    public float calculateAverage() {
        return (javaGrade + cSharpGrade + databaseGrade) / 3;
    }

    // 计算三个科目的总成绩的方法
    public float calculateTotal() {
        return javaGrade + cSharpGrade + databaseGrade;
    }

    public static void main(String[] args) {
        // 通过带参数的构造方法实例化对象
        Calculator calculator1 = new Calculator(85.0f, 90.0f, 88.0f);
        // 计算并打印平均值和总成绩
        System.out.println("通过带参构造方法创建的对象：");
        System.out.println("平均成绩: " + calculator1.calculateAverage());
        System.out.println("总成绩: " + calculator1.calculateTotal());

        // 通过无参构造方法实例化对象
        Calculator calculator2 = new Calculator();
        // 设置成绩
        calculator2.setJavaGrade(78.0f);
        calculator2.setCSharpGrade(82.0f);
        calculator2.setDatabaseGrade(80.0f);
        // 计算并打印平均值和总成绩
        System.out.println("\n通过无参构造方法创建的对象：");
        System.out.println("平均成绩: " + calculator2.calculateAverage());
        System.out.println("总成绩: " + calculator2.calculateTotal());
    }
}